/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ASTEC.DaoImpl;

import ASTEC.Dao.PersonaDao;
import ASTEC.Dominio.Persona;
import ASTEC.Util.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author PC_013
 */
public class PersonaDaoImpl implements PersonaDao {

    @Override
    public List<Persona> listarPersona() {
        List<Persona> listaPersona = new ArrayList<Persona>();
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Query query = session.createQuery("from Persona");
            listaPersona = query.list();
            session.beginTransaction().commit();
            session.close();
        } catch (Exception e) {
            session.beginTransaction().rollback();
            e.printStackTrace();
            session.close();
        }
        return listaPersona;
    }

}
